#ifndef CNC_BASE_PARAMETER_IMPLEMENTATION_H
#define CNC_BASE_PARAMETER_IMPLEMENTATION_H

#include "parameter.h"
#include <cstdint>

namespace cnc {

	namespace base {

		class ParameterImpl : public Parameter
		{
			DataTypeID typeID_;
			union {
				int8_t int8_value;
				uint8_t uint8_value;
				int16_t int16_value;
				uint16_t uint16_value;
				int32_t int32_value;
				uint32_t uint32_value;
				int64_t int64_value;
				uint64_t uint64_value;
				float float32_value;
				double float64_value;
			} data_;
		public:
			ParameterImpl() : typeID_(DT_UNSUPPORTED)
			{
			}
			void setDataType(DataTypeID typeID)
			{
				typeID_ = typeID;
			}
			virtual DataTypeID getDataType()
			{
				return typeID_;
			}
			virtual bool set(int8_t value)
			{
				if (typeID_ != DT_INT8)
					return false;
				data_.int8_value = value;
				return true;
			}
			virtual bool set(uint8_t  value)
			{
				if (typeID_ != DT_UINT8)
					return false;
				data_.uint8_value = value;
				return true;
			}
			virtual bool set(int16_t value)
			{
				if (typeID_ != DT_INT16)
					return false;
				data_.int16_value = value;
				return true;
			}
			virtual bool set(uint16_t value)
			{
				if (typeID_ != DT_UINT16)
					return false;
				data_.uint16_value = value;
				return true;
			}
			virtual bool set(int32_t value)
			{
				if (typeID_ != DT_INT32)
					return false;
				data_.int32_value = value;
				return true;
			}
			virtual bool set(uint32_t value)
			{
				if (typeID_ != DT_UINT32)
					return false;
				data_.uint32_value = value;
				return true;
			}
			virtual bool set(int64_t value)
			{
				if (typeID_ != DT_INT64)
					return false;
				data_.int64_value = value;
				return true;
			}
			virtual bool set(uint64_t value)
			{
				if (typeID_ != DT_UINT64)
					return false;
				data_.uint64_value = value;
				return true;
			}
			virtual bool set(float value)
			{
				if (typeID_ != DT_FLOAT32)
					return false;
				data_.float32_value = value;
				return true;
			}
			virtual bool set(double value)
			{
				if (typeID_ != DT_FLOAT64)
					return false;
				data_.float64_value = value;
				return true;
			}
			virtual bool get(int8_t *value)
			{
				if (typeID_ != DT_INT8)
					return false;
				*value = data_.int8_value;
				return true;
			}
			virtual bool get(uint8_t *value)
			{
				if (typeID_ != DT_UINT8)
					return false;
				*value = data_.uint8_value;
				return true;
			}
			virtual bool get(int16_t *value)
			{
				if (typeID_ != DT_INT16)
					return false;
				*value = data_.int16_value;
				return true;
			}
			virtual bool get(uint16_t *value)
			{
				if (typeID_ != DT_UINT16)
					return false;
				*value = data_.uint16_value;
				return true;
			}
			virtual bool get(int32_t *value)
			{
				if (typeID_ != DT_INT32)
					return false;
				*value = data_.int32_value;
				return true;
			}
			virtual bool get(uint32_t *value)
			{
				if (typeID_ != DT_UINT32)
					return false;
				*value = data_.uint32_value;
				return true;
			}
			virtual bool get(int64_t *value)
			{
				if (typeID_ != DT_INT64)
					return false;
				*value = data_.int64_value;
				return true;
			}
			virtual bool get(uint64_t *value)
			{
				if (typeID_ != DT_UINT64)
					return false;
				*value = data_.uint64_value;
				return true;
			}
			virtual bool get(float *value)
			{
				if (typeID_ != DT_FLOAT32)
					return false;
				*value = data_.float32_value;
				return true;
			}
			virtual bool get(double *value)
			{
				if (typeID_ != DT_FLOAT64)
					return false;
				*value = data_.float32_value;
				return true;
			}
		};

	} // namespace base

} // namespace cnc

#endif
